﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Speech.Recognition;
using System.Text;
using System.Globalization;
using System.Net;
using System.IO;
using System.Net.Mail;


namespace speech
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {



        }
        protected void Btn_SendMail_Click(object sender, EventArgs e)
        {


            WebRequest mywebReq;
            WebResponse mywebResp;
            StreamReader sr;
            string strHTML;
            StreamWriter sw;
            string lat = hiddenLat.Value;
            string lng = hiddenLng.Value;
            string message = "<h4 style =font-family:Cursive>Hello Derry Fan; </h4>" + "<h3 style= font-family:Cursive;text-align:center>Here are this weeks matches:</h3><br /><div style =text-align:center;color:white;background-color:green><br /><br />Shelbourne v UCD<br />Bohemians v St Pats<br />Bray Wanderers v Monaghan<br />Shamrock Rovers v Dundalk<br />Drogheda v Derry City<br />Cork City v Sligo Rovers<br /><br /><br /><a href=\"http://localhost:15293/Unsubscribe.aspx/\">Click Here to unsubscribe</a></div>";
            MailMessage mailObj = new MailMessage("streetspeak@hotmail.com", "X00049851@ittd.ie", "Hello",
                "This person wishes to share a location with you:Please enter in the following values at the attached page<br /> Latitude Value: " + lat + "<br />Longtitude Value: " + lng);

            //add the LinkedResource to the appropriate view

            mywebReq = WebRequest.Create("http://localhost:54363/WebForm1.aspx");
            mywebResp = mywebReq.GetResponse();
            sr = new StreamReader(mywebResp.GetResponseStream());

            strHTML = sr.ReadToEnd();
            sw = File.CreateText(Server.MapPath("ReportChange.htm"));
            sw.WriteLine(strHTML);
            sw.Close();
            //Response.WriteFile(Server.MapPath("Report.htm"));
            Attachment objAttachment = new Attachment(Server.MapPath("ReportChange.htm"));
            mailObj.Attachments.Add(objAttachment);
            mailObj.IsBodyHtml = true;
            SmtpClient SMTPServer = new SmtpClient("smtp.live.com");

            try
            {

                SMTPServer.Send(mailObj);
            }
            catch (Exception ex)
            {
                Label1.Text = ex.ToString();
            }

        }

    }
}